package com.example.tlias.service.impl;

import com.example.tlias.mapper.EmpMapper;
import com.example.tlias.pojo.Emp;
import com.example.tlias.pojo.PageBean;
import com.example.tlias.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.time.LocalDate;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    /*@Override
    public PageBean page(Integer page, Integer pageSize) {
        *//*long count = empMapper.count();
        Integer start = (page - 1) * pageSize;

        List<Emp> empList = empMapper.page(start, pageSize);*//*

        *//*
        * 使用PageHelper分页*//*

        PageHelper.startPage(page, pageSize);

        List<Emp> empList = empMapper.list();
        Page<Emp> pagee =(Page<Emp>) empList;

//        PageInfo<Emp> pagee = new PageInfo<>(empList);

        PageBean pageBean = new PageBean(pagee.getTotal(), pagee.getResult());
        return pageBean;
    }*/

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        /*
         * 使用PageHelper分页*/

        PageHelper.startPage(page, pageSize);

        List<Emp> empList = empMapper.list(name, gender, begin, end);
        Page<Emp> pagee =(Page<Emp>) empList;

//        PageInfo<Emp> pagee = new PageInfo<>(empList);

        PageBean pageBean = new PageBean(pagee.getTotal(), pagee.getResult());
        return pageBean;
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }
}
